<?php
App::import('Model', 'Pedido');
$modeloPedido = new Pedido();

App::import('Model', 'Producto');
$modeloProducto = new Producto();

App::uses('CakeNumber', 'Utility');

$idUsuario = $this->Session->read('Auth.User.id');

$datosPedido = $modeloPedido->find('first', array(
    'recursive' => 1,
    'conditions' => array(
        'Pedido.user_id' => $idUsuario,
        'Pedido.estado' => 5
    )
        ));

//debug($datosPedido);
if (!empty($datosPedido))
{
    $i = 0;
    $precioTotal = 0;
    $cantidadTotal = 0;
    foreach ($datosPedido['Item'] as $dpi)
    {
        $i++;
        $precioUnitario = $dpi['precio'];
        $cantidadUnitaria = $dpi['cantidad'];
        $precioTotal += $precioUnitario;
        $cantidadTotal += $cantidadUnitaria;
    }
}
?>
<?php if(!empty($datosPedido)): ?>
<li class="dropdown"> <a href="<?php echo $this->Html->url(array('controller' => 'productos', 'action' => 'carrito')); ?>"> <i class="fa fa-shopping-cart fa-fw"></i> <span class="hidden-sm"><?php echo $cantidadTotal; ?> Items | $<?php echo CakeNumber::currency($precioTotal, ''); ?></span></a> 
<?php else: ?>
    <li class="dropdown"> <a href="#"> <i class="fa fa-shopping-cart fa-fw"></i> <span class="hidden-sm"><?php echo $cantidadTotal; ?> Items | $<?php echo CakeNumber::currency($precioTotal, ''); ?></span></a> 
    <?php endif; ?>
    <!-- Quick Cart -->
    <div class="dropdown-menu quick-cart" id="carrito">
        <?php if (empty($datosPedido)): ?>

                <?php else: ?>
            <div class="qc-row qc-row-heading"> <span class="qc-col-qty">QTY.</span> <span class="qc-col-name"><?php echo $cantidadTotal; ?> items in bag</span> <span class="qc-col-price">$<?php
                    echo CakeNumber::currency($precioTotal, '');
                    ;
                    ?></span> </div>
    <?php foreach ($datosPedido['Item'] as $dpi): ?>
        <?php //debug($datosPedido);   ?>
                <div class="qc-row qc-row-item"> 
                    <span class="qc-col-qty"><?php echo $dpi['cantidad']; ?></span> 
                    <span class="qc-col-name">
                        <a href="#">
                            <?php
                            //debug($dpi); 
                            $idProducto = $dpi['producto_id'];
                            $datosProducto = $modeloProducto->findById($idProducto, null, null, null, null, -1);
                            echo $datosProducto['Producto']['nombre'];
                            ?>
                        </a>
                    </span> 
                    <span class="qc-col-price">$<?php echo $dpi['precio']; ?></span> 
            <!--        <span class="qc-col-remove"> <i class="fa fa-times fa-fw"></i> </span> -->
                </div>
            <!--    <div class="qc-row qc-row-item"> <span class="qc-col-qty">1</span> <span class="qc-col-name"><a href="#a">Women Fashion hot Wear item</a></span> <span class="qc-col-price">$800</span> <span class="qc-col-remove"> <i class="fa fa-times fa-fw"></i> </span> </div>
                <div class="qc-row qc-row-item"> <span class="qc-col-qty">3</span> <span class="qc-col-name"><a href="#a">Women Fashion hot Wear item</a></span> <span class="qc-col-price">$252.25</span> <span class="qc-col-remove"> <i class="fa fa-times fa-fw"></i> </span> </div>-->
    <?php endforeach; ?>
        <div class="qc-row-bottom"><a class="btn qc-btn-viewcart" href="<?php echo $this->Html->url(array('controller'=>'productos', 'action'=>'carrito')); ?>">view
                    cart</a><a class="btn qc-btn-checkout" href="<?php echo $this->Html->url(array('controller'=>'productos', 'action'=>'carrito')); ?>">check
                    out</a></div>
<?php endif; ?>

    </div>
    <!-- end: Quick Cart --> 
</li>